package org.longkey.portal
{
	import flash.display.MovieClip;
	
	import mx.controls.SWFLoader;
	import mx.core.UIComponent;
	
	import spark.components.BorderContainer;
	import spark.components.Group;
	import spark.components.Image;
	import spark.components.Label;
	import spark.layouts.HorizontalLayout;
	import spark.layouts.VerticalLayout;
	
	
	public class Mask extends BorderContainer
	{
		public static const INFO:int = 0;
		public static const WAIT:int = 1;
		public static const OK:int = 2;
		public static const ERROR:int = 3;
		
		[Embed(source="/org/longkey/portal/ok_64.png")]
		private var OKIcon:Class;
		
		[Embed(source="/org/longkey/portal/error_64.png")]
		private var ErrorIcon:Class;
		
		[Embed(source="/org/longkey/portal/loading9.swf")]
		private var LoadingMovie:Class;
		
		public function Mask()
		{
			super();
			
			this.setStyle("cornerRadius", 10);
			this.setStyle("borderWeight", 1);
			this.setStyle("backgroundAlpha", 0);
//			this.alpha = 0.5;
			this.height = 100;
			this.width = 100;
			var hl:HorizontalLayout = new HorizontalLayout();
			hl.horizontalAlign = "center";
			hl.verticalAlign = "middle";
			hl.gap = 6;
			hl.paddingLeft = 5;
			hl.paddingBottom = 5;
			hl.paddingRight = 5;
			hl.paddingTop = 5;
			this.layout = hl;
		}
		
		public function apply(msg:String, type:int):void{
			this.removeAllElements();
			var media:UIComponent = null;
			var wid:Number = 0;
			switch(type){
				case Mask.WAIT:
					var swf:SWFLoader = new SWFLoader();
					swf.source = this.LoadingMovie;
					swf.setStyle("chromeColor", 0x00FF00);
					media = swf;
					break;
				case Mask.OK:
					var img:Image = new Image();
					img.source = this.OKIcon;
					media = img;
					break;
				case Mask.ERROR:
					img = new Image();
					img.source = this.ErrorIcon;
					media = img;
					break;
				default:
					break;
			}
			if(media != null){
				media.alpha = 1;
				this.addElement(media);
				wid += 64 + 6;
			}
			if(msg != null && msg != ""){
				var lab:Label = new Label();
				lab.maxDisplayedLines = 3;
				lab.text = msg;
				lab.alpha = 1;
				this.addElement(lab);
				wid += 200;
				this.setStyle("borderAlpha", 1);
			}	
			else{
				this.setStyle("borderAlpha", 0);
			}
			wid += 10;
			this.width = wid;
		}
	}
}